-- Delete database entries for guests who where incomplete removed with the release of 4.7.1.0
DELETE a.* FROM admin_access_users AS a LEFT JOIN `customers` AS c ON (a.customer_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_basket AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_basket_attributes AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_info AS a LEFT JOIN `customers` AS c ON (a.customers_info_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_ip AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_status_history AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_wishlist AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM customers_wishlist_attributes AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM coupon_gv_customer AS a LEFT JOIN `customers` AS c ON (a.customer_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM gm_gprint_cart_elements AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM gm_gprint_wishlist_elements AS a LEFT JOIN `customers` AS c ON (a.customers_id = c.customers_id) WHERE c.customers_id IS NULL;
DELETE a.* FROM whos_online AS a LEFT JOIN `customers` AS c ON (a.customer_id = c.customers_id) WHERE c.customers_id IS NULL;

-- Setting customer id to 0 for database entries for guests who where incomplete removed with the release of 4.7.1.0
UPDATE coupon_gv_queue AS a LEFT JOIN customers AS c ON (a.customer_id = c.customers_id) SET a.customer_id=0 WHERE c.customers_id IS NULL;
UPDATE coupon_redeem_track AS a LEFT JOIN customers AS c ON (a.customer_id = c.customers_id) SET a.customer_id=0 WHERE c.customers_id IS NULL;
UPDATE gm_gprint_uploads AS a LEFT JOIN customers AS c ON (a.customers_id = c.customers_id) SET a.customers_id=0 WHERE c.customers_id IS NULL;
UPDATE newsletter_recipients AS a LEFT JOIN customers AS c ON (a.customers_id = c.customers_id) SET a.customers_id=0 WHERE c.customers_id IS NULL;
UPDATE orders AS a LEFT JOIN customers AS c ON (a.customers_id = c.customers_id) SET a.customers_id=0 WHERE c.customers_id IS NULL;
UPDATE withdrawals AS a LEFT JOIN customers AS c ON (a.customer_id = c.customers_id) SET a.customer_id=NULL WHERE a.customer_id IS NOT NULL AND c.customers_id IS NULL;

ALTER TABLE `customers_memo` CHANGE `memo_date` `memo_date` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00';
UPDATE address_book SET `entry_company` = "" WHERE `entry_company` IS NULL;
ALTER TABLE `address_book` CHANGE `entry_company` `entry_company` VARCHAR(255) NOT NULL DEFAULT '';

UPDATE `customers` SET `shipping_unallowed` = REPLACE(`shipping_unallowed`, ' ', ''), `payment_unallowed` = REPLACE(`payment_unallowed`, ' ', '');
